package com.huitone.smspfm.model;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.huitone.smspfm.logger.ExtLogger;
import org.springframework.data.redis.serializer.StringRedisSerializer;

import com.bin.common.utils.StringUtils;
import com.huitone.smspfm.redis.model.AppCanstant;

/**   
* @Title SmsEntityForMt.java 
* @Package com.huitone.smspfm.model 
* @Description TODO(用一句话描述该文件做什么) 
* @author ybliang   
* @date 2017年9月10日 下午7:00:05 
* @version V1.0   
*/
public class SmsEntityForMt {
	
	private static ExtLogger logger = ExtLogger.create(SmsEntityForMt.class);
	
	private StringRedisSerializer serializer = new StringRedisSerializer();

	private String serialno = null;
	
	private String srvNode = null;
	private String serviceCode = null;
	private String smType = null;
	private String phoneNumber = null;
	private String content = null;
	private String reportFlag = null;
	private String recvTime = null;
	private String recvModuleName = null;
	private String sendPort = null;
	private String serialSegment = null;
	private String respResult = null;
	private String respTime = null;
	private String orgSerialNo = null;
	private String orgSrvNode = null;
	private String sendFeedbackResult = null;
	
	private String conSm = null;
	private String gateLinkId = null;
	
	
	private boolean intercepted = false;
	
	private String interceptedCode = "";
	private String interceptedDesc = "";
	
	private boolean isforbidsms = false;
	
	/**
	 * for task
	 */
	private Map<String, Integer> dealResultCodeMap = new HashMap<>();
	
	/**
	 * only for repeat task
	 */
	private List<List<String>> repeatEncodes = new ArrayList<List<String>>(); 
	private Long forbidTimeEnd = 0L;
	
	/**
	 * only for attach task
	 */
	private String attachInfo = null;
	private Long attachExpireTime = 0L;
	
	/**
	 * only for sms route task
	 */
	private String priListName = null;
	
	public Map<byte[], byte[]> getMapB() {
		
		Map<byte[], byte[]> map = new HashMap<>();
		
		map.put(AppCanstant.SmsEntity.Srv_node, serializer.serialize(StringUtils.toString(srvNode)));
		map.put(AppCanstant.SmsEntity.ServiceCode, serializer.serialize(StringUtils.toString(serviceCode)));
		map.put(AppCanstant.SmsEntity.SmType, serializer.serialize(StringUtils.toString(smType)));
		map.put(AppCanstant.SmsEntity.User, serializer.serialize(StringUtils.toString(phoneNumber)));
		map.put(AppCanstant.SmsEntity.Smcont, serializer.serialize(StringUtils.toString(content)));
		map.put(AppCanstant.SmsEntity.Reportflag, serializer.serialize(StringUtils.toString(reportFlag)));
		map.put(AppCanstant.SmsEntity.recvTime, serializer.serialize(StringUtils.toString(recvTime)));
		map.put(AppCanstant.SmsEntity.RecvModuleName, serializer.serialize(StringUtils.toString(recvModuleName)));
		map.put(AppCanstant.SmsEntity.SendPort, serializer.serialize(StringUtils.toString(sendPort)));
		map.put(AppCanstant.SmsEntity.SerialSegment, serializer.serialize(StringUtils.toString(serialSegment)));
		map.put(AppCanstant.SmsEntity.respresult, serializer.serialize(StringUtils.toString(respResult)));
		map.put(AppCanstant.SmsEntity.resptime, serializer.serialize(StringUtils.toString(respTime)));
		map.put(AppCanstant.SmsEntity.OrgSerialNo, serializer.serialize(StringUtils.toString(orgSerialNo)));
		map.put(AppCanstant.SmsEntity.OrgSrvNode, serializer.serialize(StringUtils.toString(orgSrvNode)));
		map.put(AppCanstant.SmsEntity.SendFeedbackResult, serializer.serialize(StringUtils.toString(sendFeedbackResult)));
		map.put(AppCanstant.SmsEntity.ConSm, serializer.serialize(StringUtils.toString(conSm)));
		map.put(AppCanstant.SmsEntity.GateLinkId, serializer.serialize(StringUtils.toString(gateLinkId)));
		
		return map;
	}
	
	public static SmsEntityForMt parse(List<String> list) {
		
		SmsEntityForMt smsEntityForMt = null;
		
		if (list != null) {
			
			if (list.size() >= 15) {
				smsEntityForMt = new SmsEntityForMt();
				smsEntityForMt.setSrvNode(list.get(0));
				smsEntityForMt.setServiceCode(list.get(1));
				smsEntityForMt.setSmType(list.get(2));
				smsEntityForMt.setPhoneNumber(list.get(3));
				smsEntityForMt.setContent(list.get(4));
				smsEntityForMt.setReportFlag(list.get(5));
				smsEntityForMt.setRecvTime(list.get(6));
				smsEntityForMt.setRecvModuleName(list.get(7));
				smsEntityForMt.setSendPort(list.get(8));
				smsEntityForMt.setSerialSegment(list.get(9));
				smsEntityForMt.setRespTime(list.get(10));
				smsEntityForMt.setRespResult(list.get(11));
				smsEntityForMt.setOrgSrvNode(list.get(12));
				smsEntityForMt.setOrgSerialNo(list.get(13));
				smsEntityForMt.setSendFeedbackResult(list.get(14));
				
				smsEntityForMt.setSerialno(smsEntityForMt.getSerialSegment().replaceAll(",", ""));
			} else {
				logger.error("SmsEntityForMt缺少参数");
			}
		}
		
		return smsEntityForMt;
		
	}
	
	public static List<Object> getColumns() {
		List<Object> hashKeys = new ArrayList<>();
		hashKeys.add("Srv_node");
		hashKeys.add("ServiceCode");
		hashKeys.add("SmType");
		hashKeys.add("User");
		hashKeys.add("Smcont");
		hashKeys.add("Reportflag");
		hashKeys.add("recvTime");
		hashKeys.add("RecvModuleName");
		hashKeys.add("SendPort");
		hashKeys.add("SerialSegment");
		hashKeys.add("resptime");
		hashKeys.add("respresult");
		hashKeys.add("OrgSrvNode");
		hashKeys.add("OrgSerialNo");
		hashKeys.add("SendFeedbackResult");
		return hashKeys;
	}
	
	public String getSrvNode() {
		return srvNode;
	}
	public void setSrvNode(String srvNode) {
		this.srvNode = srvNode;
	}
	public String getServiceCode() {
		return serviceCode;
	}
	public void setServiceCode(String serviceCode) {
		this.serviceCode = serviceCode;
	}
	public String getSmType() {
		return smType;
	}
	public void setSmType(String smType) {
		this.smType = smType;
	}
	public String getPhoneNumber() {
		return phoneNumber;
	}
	public void setPhoneNumber(String phoneNumber) {
		this.phoneNumber = phoneNumber;
	}
	public String getContent() {
		return content;
	}
	public void setContent(String content) {
		this.content = content;
	}
	public String getRecvModuleName() {
		return recvModuleName;
	}
	public void setRecvModuleName(String recvModuleName) {
		this.recvModuleName = recvModuleName;
	}
	public String getSendPort() {
		return sendPort;
	}
	public void setSendPort(String sendPort) {
		this.sendPort = sendPort;
	}
	public String getSerialSegment() {
		return serialSegment;
	}
	public void setSerialSegment(String serialSegment) {
		this.serialSegment = serialSegment;
	}
	public String getRespResult() {
		return respResult;
	}
	public void setRespResult(String respResult) {
		this.respResult = respResult;
	}
	public String getOrgSerialNo() {
		return orgSerialNo;
	}
	public void setOrgSerialNo(String orgSerialNo) {
		this.orgSerialNo = orgSerialNo;
	}
	public String getOrgSrvNode() {
		return orgSrvNode;
	}
	public void setOrgSrvNode(String orgSrvNode) {
		this.orgSrvNode = orgSrvNode;
	}
	public String getSendFeedbackResult() {
		return sendFeedbackResult;
	}
	public void setSendFeedbackResult(String sendFeedbackResult) {
		this.sendFeedbackResult = sendFeedbackResult;
	}
	public String getSerialno() {
		return serialno;
	}
	public void setSerialno(String serialno) {
		this.serialno = serialno;
	}

	public String getReportFlag() {
		return reportFlag;
	}

	public void setReportFlag(String reportFlag) {
		this.reportFlag = reportFlag;
	}

	public String getRecvTime() {
		return recvTime;
	}

	public void setRecvTime(String recvTime) {
		this.recvTime = recvTime;
	}

	public String getRespTime() {
		return respTime;
	}

	public void setRespTime(String respTime) {
		this.respTime = respTime;
	}

	public Map<String, Integer> getDealResultCodeMap() {
		return dealResultCodeMap;
	}
	
	public void setDealResultCodeMap(String key, Integer Code) {
		dealResultCodeMap.put(key, Code);
	}

	public List<List<String>> getRepeatEncodes() {
		return repeatEncodes;
	}

	public void setRepeatEncodes(List<List<String>> repeatEncodes) {
		this.repeatEncodes = repeatEncodes;
	}

	public Long getForbidTimeEnd() {
		return forbidTimeEnd;
	}

	public void setForbidTimeEnd(Long forbidTimeEnd) {
		this.forbidTimeEnd = forbidTimeEnd;
	}

	public String getConSm() {
		return conSm;
	}

	public void setConSm(String conSm) {
		this.conSm = conSm;
	}

	public String getAttachInfo() {
		return attachInfo;
	}

	public void setAttachInfo(String attachInfo) {
		this.attachInfo = attachInfo;
	}

	public Long getAttachExpireTime() {
		return attachExpireTime;
	}

	public void setAttachExpireTime(Long attachExpireTime) {
		this.attachExpireTime = attachExpireTime;
	}

	public String getGateLinkId() {
		return gateLinkId;
	}

	public void setGateLinkId(String gateLinkId) {
		this.gateLinkId = gateLinkId;
	}

	public String getPriListName() {
		return priListName;
	}

	public void setPriListName(String priListName) {
		this.priListName = priListName;
	}

	public boolean isIntercepted() {
		return intercepted;
	}

	public void setIntercepted(boolean intercepted) {
		this.intercepted = intercepted;
	}

	public boolean isIsforbidsms() {
		return isforbidsms;
	}

	public void setIsforbidsms(boolean isforbidsms) {
		this.isforbidsms = isforbidsms;
	}

	public String getInterceptedCode() {
		return interceptedCode;
	}

	public void setInterceptedCode(int interceptedCode) {
		
		if (StringUtils.isEmpty(this.interceptedCode)) {
			this.interceptedCode += interceptedCode;
		} else {
			this.interceptedCode += ":" + interceptedCode;
		}
		
	}

	public String getInterceptedDesc() {
		return interceptedDesc;
	}

	public void setInterceptedDesc(String interceptedDesc) {
		
		if (StringUtils.isEmpty(this.interceptedDesc)) {
			this.interceptedDesc += interceptedDesc;
		} else {
			this.interceptedDesc += ":" + interceptedDesc;
		}
	}
}
